package com.zz.ecommerce.declareManage.exportB2BDeclare.exchangeSettlementManager.service;

import com.zz.ecommerce.baseManage.baseDict.dao.BaseDictDao;
import com.zz.ecommerce.common.CommonDao;
import com.zz.ecommerce.declareManage.exportB2BDeclare.exchangeSettlementManager.bean.TExchangeSettlement;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by admin on 2016/3/31.
 */
@Service
public class TExchangeSettlementService {
    @Autowired
    CommonDao commonDao;
    @Autowired
    BaseDictDao baseDictDao;

    /**
     * 保存结汇信息，如果存在indx则更新，否则新增
     *
     * @param exchangeSettlement
     * @return
     */
    public String saveExchangeSettlement(TExchangeSettlement exchangeSettlement) {
        if (StringUtils.isEmpty(exchangeSettlement.getIndx())) {
            commonDao.insert("t_exchange_settlement", exchangeSettlement);
        } else {
            commonDao.update("t_exchange_settlement", exchangeSettlement, "where indx=#{updateObj.indx}");
        }
        return "success";
    }

    /**
     * 删除结汇信息
     *
     * @param indxs
     * @return
     */
    public String deleteExchangeSettlement(String indxs) {
        if (StringUtils.isNotEmpty(indxs)) {
            String ids[] = indxs.split(",");
            for (String id : ids) {
                if (StringUtils.isNotEmpty(id)) {
                    baseDictDao.updateBySql("update t_exchange_settlement set enable='0' where indx='" + id + "'");
                }
            }
        }
        return "success";
    }

    /**
     * 申报结汇信息
     *
     * @param indxs
     * @return
     */
    public String decExchangeSettlement(String indxs) {
        if (StringUtils.isNotEmpty(indxs)) {
            String ids[] = indxs.split(",");
            for (String id : ids) {
                if (StringUtils.isNotEmpty(id)) {
                    baseDictDao.updateBySql("update t_exchange_settlement set status='申报成功',status_time=sysdate where indx='" + id + "'");
                }
            }
        }
        return "success";
    }
}
